


#ifndef __TASK_COMM_H__
#define __TASK_COMM_H__ 

#include <QRunnable>
#include <QObject>
#include <QString>
#include "ev_serial.h"

class TaskCommBase : public QObject, public QRunnable
{
    Q_OBJECT

public:
    explicit TaskCommBase(EvSerial *serial);

signals:
    void progressUpdated(int value);
    void messageLogged(QString message);
    void finished(bool success);

protected:
    /* return: ==0  success
     * return: > 0  device returned error code
     * return: -1   send packet failed
     * return: -2   recv packet timeout
     * return: -3   recv packet error(seq/cmd/len, etc)
    */
    int callGetVersion( uint8_t type,
                        uint8_t *major,
                        uint8_t *minor,
                        uint8_t *patch,
                        uint32_t *build_time,
                        uint32_t *firm_len);
    int callReset(uint32_t delay_ms);

    int callOtaRead(uint32_t index, uint8_t *data); // len of data is EV_CALL_OTA_DATA_LEN
    int callOtaStart(uint32_t firm_len);
    int callOtaData(uint32_t index, const uint8_t *data); // len of data is EV_CALL_OTA_DATA_LEN
    int callOtaEnd();
    int callSendCommand(int cmd_id, const QByteArray &data);

protected:
    EvSerial *m_serial;
    uint8_t seq;
};

#endif /* __TASK_COMM_H__ */
